<?php

namespace App\Admin\Extensions\Tools;

use App\Models\Factory;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;

class ShenheAction extends BatchAction
{
    protected $action;

    public function __construct($title = null, $action = 1)
    {
        $this->title = $title;
        $this->action = $action;
    }
    // 确认弹窗信息
    public function confirm()
    {
        if ($this->action==1){
            return '您确定要审核通过已选中的商铺吗？';
        }else{
            return '您确定要审核不通过已选中的商铺吗？';
        }
    }

    // 处理请求
    public function handle(Request $request)
    {
        // 获取选中的文章ID数组
        $keys = $this->getKey();

        // 获取请求参数
        $action = $request->get('action');

        foreach (Factory::find($keys) as $post) {
            $post->shenhe = $action;
            $post->save();
        }
        if ($action==1){
            $message = '浦源审核通过';
        }elseif ($action==2){
            $message='浦源审核不通过';
        }


        return $this->response()->success($message)->refresh();
    }

    // 设置请求参数
    public function parameters()
    {
        return [
            'action' => $this->action,
        ];
    }

}
